//
//  ZQProcessedOrderPage.m
//  jianzhik
//
//  Created by huami on 2018/8/30.
//  Copyright © 2018年 WKWebView. All rights reserved.
//
#import "BRPickerView.h"
#import "ZQProcessedOrderPage.h"
#import "ZQPendingOrderTableViewCell.h"
#import "UIBarButtonItem+item.h"
#import <MJExtension/MJExtension.h>
@interface ZQProcessedOrderPage ()
/** listMuArr */
@property (nonatomic, strong) NSMutableArray *listMuArr;
/** status */
@property (nonatomic, strong) NSNumber *status;
/** rightItemTitle */
@property (nonatomic, copy) NSString *rightItemTitle;
@end

@implementation ZQProcessedOrderPage


- (NSMutableArray *)listMuArr
{
    if (!_listMuArr) {
        _listMuArr = [[NSMutableArray alloc] init];
    }
    return _listMuArr;
}

- (NSNumber *)status
{
    if (!_status) {
        _status = [[NSNumber alloc] init];
    }
    return _status;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self networkRequest:self.status];
        [self setUpNavBar];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    [self registerCell:[ZQPendingOrderTableViewCell class]];
    self.tableView.backgroundColor = [UIColor stringToColor:@"#d7d7d7"];
    self.tableView.contentInset = UIEdgeInsetsMake(10, 0, 0, 0);
    self.status = @11;

    self.rightItemTitle = @"所有状态";

}

- (NSNumber *)valueWithDict:(NSString *)str
{
    NSDictionary *dict = @{
                           @"所有状态"    : @11,
                           @"待确认列表" : @20,
                           @"失败列表"    : @30,
                           @"已确认列表" : @40
                           };
    return dict[str];
}

- (void)editClick
{
    
    NSArray *dataSource = @[@"所有状态",@"待确认列表",@"已确认列表",@"失败列表"];
    [BRStringPickerView showStringPickerWithTitle:@"类型" dataSource:dataSource defaultSelValue:self.rightItemTitle isAutoSelect:NO themeColor:kTinColor resultBlock:^(id selectValue) {
        self.rightItemTitle = selectValue;
        self.navigationItem.rightBarButtonItem = [UIBarButtonItem backItemWithImage:nil hightImage:nil target:self action:@selector(editClick) title:selectValue];
        [self networkRequest:[self valueWithDict:selectValue]];
        NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
        parameters[@"Status"] = [self valueWithDict:selectValue];
    } cancelBlock:^{
        NSLog(@"点击了背景视图或取消按钮");
    }];
}

- (void)networkRequest:(NSNumber *)parameter
{
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    parameters[@"Status"] = parameter;
    [ZQAFHelper afnetworkRequestWithPostURL:@"/v1/work/listwork" parameters:parameters view:self.view finishedBlcok:^(NSDictionary *dict) {
        //        dict[Data]
        NSArray *arr = dict[@"Data"];
        if (arr.count == 0) {
            [UIHelper showTipsWithText:@"查无数据" inView:self.view];
            [self.listMuArr removeAllObjects];
            [self.tableView reloadData];
            return ;
        }
        self.listMuArr = [ZQPendingModel mj_objectArrayWithKeyValuesArray:dict[@"Data"]];
        [UIHelper dismissLoadingInView:self.view];
        [self.tableView reloadData];
    }];
}

- (void)setUpNavBar
{
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem backItemWithImage:nil hightImage:nil target:self action:@selector(editClick) title:@"所有状态"];
    // titleview search_big searchWorkInfo
    //    self.navigationItem.title =  @"首页";
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    switch (self.status.intValue) {
        case 11:
            return self.listMuArr.count > 20 ? 20 : self.listMuArr.count;
            break;
        case 10:
            return self.listMuArr.count > 20 ? 20 : self.listMuArr.count;
            break;
            break;
        case 20 : case 30 : case 40:
            return 10;
            break;
        default: return 10;
            break;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 139;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ZQPendingOrderTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellID  forIndexPath:indexPath];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    cell.penModel = self.listMuArr[indexPath.row];
    return cell;
}

@end
